package com.aode.music.repository;

import android.app.Application;
import android.util.Log;

import androidx.lifecycle.MutableLiveData;

import com.aode.common.bean.request.ChatData;
import com.aode.common.bean.request.LoginData;
import com.aode.common.bean.request.SearchData;
import com.aode.common.bean.response.Mllist;
import com.aode.common.bean.response.Music;
import com.aode.common.bean.response.News;
import com.aode.common.bean.response.User;
import com.aode.common.bean.web.Page;
import com.aode.common.bean.web.Result;
import com.aode.music.network.HttpData;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class WebRepository {

    private MutableLiveData<Result> resultMutableLiveData = new MutableLiveData<>();
    private MutableLiveData<Result<User>> userMutableLiveData = new MutableLiveData<>();
    private MutableLiveData<Result<Page<Mllist>>> mllistMutableLiveData = new MutableLiveData<>();
    private  MutableLiveData<Result<Page<Music>>> musicMutableLiveData = new MutableLiveData<>();
    private  MutableLiveData<Result<Page<Music>>> musicMutableLiveData1 = new MutableLiveData<>();
    private MutableLiveData<Result<User>> userMutableLiveData1 = new MutableLiveData<>();
    //测试
    private MutableLiveData<List<News>>  newsMutableLiveData = new MutableLiveData<>();



    private Application application;
    public WebRepository(Application application){
        this.application = application;
    }

    public void getUser(SearchData searchData){
        userMutableLiveData1 = HttpData.getUser(searchData);
    }

    public MutableLiveData<Result<User>> getUserMutableLiveData1(){
        return userMutableLiveData1;
    }

    public void register(LoginData loginData){
        resultMutableLiveData = HttpData.Register(loginData);
    }
    public MutableLiveData<Result> getResultMutableLiveData(){
        return resultMutableLiveData;
    }



    public void Login(LoginData loginData){
        userMutableLiveData = HttpData.Login(loginData);
    }

    public MutableLiveData<Result<User>> getLoginMutableLiveData(){
        return userMutableLiveData;
    }

    public void getMllist(SearchData searchData){
        mllistMutableLiveData = HttpData.getMllist(searchData);
    }

    public MutableLiveData<Result<Page<Mllist>>> getMllistMutableLiveData(){
        return mllistMutableLiveData;
    }
    public void getMusic(SearchData searchData){
        musicMutableLiveData = HttpData.getMusic(searchData);
    }

    public MutableLiveData<Result<Page<Music>>> getMusicLiveData(){
        return musicMutableLiveData;
    }

    public void getMusic1(SearchData searchData){
        musicMutableLiveData1 = HttpData.getMusic1(searchData);
    }

    public MutableLiveData<Result<Page<Music>>> getMusicLiveData1(){
        return musicMutableLiveData1;
    }

    public void getNews(ChatData chatData){
        List<News> newsList = new ArrayList<>();

        for(int i = 0;i < 10;i++){
            News news = new News();
            news.setFromUserNam("fromuser"+i);
            news.setFromUserAvatar("/files/5dc0a8cbeaab430f90ec6f05eb5199c7_16396181139634672.png");
            news.setToUserAvatar("/files/5ace757223004dcfb42840090a4b0827_yisheng.jpg");
            news.setToUserName("touser"+i);

            ArrayList<String> stringList = new ArrayList<>();
            ArrayList<Boolean> booleans = new ArrayList<>();
            for(int j = 0;j < 10;j++){
                stringList.add(j+"");
                if(j<=5){
                    booleans.add(true);
                }else{
                    booleans.add(false);
                }
            }
            news.setIsSend(booleans);
            news.setDate(new Date().toString());
            news.setContent(stringList);
            newsList.add(news);
        }
        newsMutableLiveData.setValue(newsList);
    }
    public MutableLiveData<List<News>> getNewsMutableLiveData(){
        return newsMutableLiveData;
    }
}
